home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
misc_pto
/
anaglph
/
anahid.bas
next >
Wrap
BASIC Source File
|
1991-10-24
|
4KB
|
99 lines
REM ANAGLYPH (HIDDEN LINES REMOVED)--------1024x768
'$INCLUDE: 'gxlib.bas'
'$INCLUDE: 'grlib.bas'
retcode% = gxSetDisplay%(gxTS.38)
retcode% = gxSetMode%(gxTEXT)
PI = 3.1416: OOB = 0
INPUT "E,D,A,B,XI,XF,DX,YI,YF,DY "; E, D, A, B, XI, XF, DX, YI, YF, DY
INPUT "Amp,Dec,Freq "; TI, U, V
A = PI * A / 180: B = PI * B / 180
cosa = COS(A): cosb = COS(B): sina = SIN(A): sinb = SIN(B)
retcode% = gxSetMode%(gxGRAPHICS)
retcode% = grSetViewPort%(0, 0, 1023, 767)
retcode% = grSetViewWorld%(-511, -383, 511, 383)
retcode% = grSetWorld%(gxTRUE)
retcode% = grClearViewPort%
FOR image = 1 TO 2 ' two different perspectives
FOR mesh = 1 TO 2
FOR x = XI TO XF STEP DX: XSQ = x * x
FOR y = YI TO YF STEP DY: YSQ = y * y
IF image = 1 THEN COLOUR = 4 ELSE COLOUR = 1
'************ surface equation *********
Z1 = TI * (EXP(-(U * ((XSQ) + (YSQ)))))
Z2 = COS(V * (SQR((XSQ) + (YSQ))))
Z = Z1 * Z2
'***************************************
'**************************** Alpha/Beta rotation equations ********
XAB = x * cosa * cosb - y * sina * cosb + Z * sinb
YAB = x * sina + y * cosa
ZAB = -x * cosa * sinb + y * sina * sinb + Z * cosb
'*******************************************************************
'*********************** screen projections ************************
TL = D / (D - XAB)
YP = CINT(E + ((YAB - E) * TL))
ZP = CINT(ZAB * TL)
'*******************************************************************
'***************************** Don't waste time replotting *********
PCOLOR% = grGetPixel%(YP, ZP)
IF image = 1 AND PCOLOR% = 4 THEN GOTO 7
IF image = 2 AND PCOLOR% = 1 THEN GOTO 7
IF image = 2 AND PCOLOR% = 4 THEN COLOUR = 5
IF image = 2 AND PCOLOR% = 5 THEN GOTO 7
'*******************************************************************
dist = SQR(((XAB - D) * (XAB - D)) + ((YAB - E) * (YAB - E)) + (ZAB * ZAB))
STP = -(30 / dist): RES = 1 'initally coarse step
TAL = 0
222 FOR t = 1 TO 0 STEP STP 'scan in surface-to-eye direction
TAL = TAL + 1
'******************************* 3D line equations *****************
xl = D + ((XAB - D) * t)
yl = E + ((YAB - E) * t)
zl = ZAB * t
'*******************************************************************
'************************** unrotate: Beta/Alpha sequence **********
sina = -sina: sinb = -sinb
XBA = xl * cosa * cosb - yl * sina + zl * cosa * sinb
YBA = xl * sina * cosb + yl * cosa + zl * sina * sinb
ZBA = -xl * sinb + zl * cosb
sina = -sina: sinb = -sinb
'*******************************************************************
'*********************** unrotate surface point ********************
zuna = TI * (EXP(-(U * ((XBA * XBA) + (YBA * YBA)))))
zunb = COS(V * (SQR((XBA * XBA) + (YBA * YBA))))
zun = zuna * zunb
'*******************************************************************
diff = SGN(CINT(ZBA) - CINT(zun)) 'reference line point to surface
IF TAL < 3 THEN GOTO 22 'escape surface tension
IF TAL = 3 THEN ref = diff
IF diff - ref <> 0 THEN GOTO 7 'point is hidden
'***** set hi-res line scan and check for out of bounds (OOB) ******
IF ((XBA >= XF) OR (XBA <= XI) OR (YBA >= YF) OR (YBA <= YI)) THEN OOB = 1
IF (OOB = 1) AND (RES = 1) THEN STP = STP / 64: TAL = 0: RES = 0: GOTO 222
IF (OOB = 1) AND (RES = 0) THEN retcode% = grPutPixel%(YP, ZP, COLOUR): OOB = 0: EXIT FOR
'*******************************************************************
22 NEXT t
7 NEXT y, x
SWAP DX, DY
NEXT mesh
E = -E 'switch eyes
NEXT image
BEEP
DO: LOOP WHILE INKEY$ = ""
retcode% = gxSetMode%(gxTEXT)
END